﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

namespace $safeprojectname$
{
    /// <summary>
    ///     The application common way how to clear cached data (static)
    /// </summary>
    public class ResetCacheFacade : Facade, IResetCacheFacade
    {
        #region public Reset
        /// <summary>
        ///     When called every Facade's Change event is risen
        /// </summary>
        /// <param name = "sender"></param>
        public virtual void ResetStaticCaches(object sender)
        {
            OnResetStaticCaches(sender);
        }

        public static void OnResetStaticCaches(object sender)
        {
            foreach (var change in Changes)
            {
                change(sender, new EventArgs());
            }
        }
        #endregion public Reset

        #region static
        /// <summary>
        ///     Collection of static listeners - which could be call to reset static-cache.
        ///     They are gathered from all Facade operation on this - ONE place.
        /// </summary>
        static readonly IList<EventHandler> Changes = new List<EventHandler>();

        /// <summary>
        ///     Attention! Only static method-delegates can be appended to that handler
        ///     Every Facade appends to that handler
        ///     And therefore can be called via ResetCache
        /// </summary>
        public static EventHandler ResetAll
        {
            get { return null; }
            set
            {
                if (!value.Method.IsStatic)
                {
                    return;
                }
                if (!Changes.Contains(value))
                {
                    Changes.Add(value);
                }
            }
        }
        #endregion static
    }
}